# 导入urlopen
from urllib.request import urlopen
# 导入urlretrieve函数，用于下载图片
from urllib.request import urlretrieve

# 导入BeautifulSoup
from bs4 import BeautifulSoup as bf

# 请求获取HTML
html = urlopen("http://www.baidu.com/")
# 用BeautifulSoup解析html
obj = bf(html.read(),'html.parser')
# 从标签head、title里提取标题
title = obj.head.title
# 只提取logo图片的信息
logo_pic_info = obj.find_all('img',class_="index-logo-src")
# 提取logo图片的链接
logo_url = "http:"+logo_pic_info[0]['src']
# 使用urlretrieve下载图片
urlretrieve(logo_url, 'logo.png')
# # 打印标题
# print(title)
# 分别打印每个图片的信息
# for i in img_info:
#     print(i)
# 打印链接
# print(logo_url)

